package com.miracle.login.module.mvp.model;

import com.miracle.basemvp.base.BaseModel;
import com.miracle.basemvp.base.BaseResponse;
import com.miracle.basemvp.lifecycle.rx.RxSchedulersHelper;
import com.miracle.basemvp.network.IRetrofitManager;
import com.miracle.common.bean.User.User;
import com.miracle.common.mvp.entity.request.CheckVersionRequest;
import com.miracle.common.mvp.entity.response.DandelionResponse;
import com.miracle.common.mvp.entity.response.VersionInfo;
import com.miracle.login.module.api.LoginApi;
import com.miracle.login.module.mvp.contract.LoginContract;
import com.miracle.login.module.mvp.entity.request.LoginRequest;
import com.miracle.login.module.mvp.entity.response.LoginResponse;

import javax.inject.Inject;

import io.reactivex.Observable;

/**
 * com.miracle.login.module.mvp.model
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/6/29 16:28
 * @see com.miracle.login.module.mvp.model
 */
public class LoginModel extends BaseModel implements LoginContract.Model {

    @Inject
    public LoginModel(IRetrofitManager retrofitManager) {
        super(retrofitManager);
    }

    @Override
    public Observable<BaseResponse<User>> login(LoginRequest request) {
        return mRetrofitManager
                .obtainRetrofitService(LoginApi.class)
                .login(request)
                .compose(RxSchedulersHelper.<BaseResponse<User>>io_main());
    }

    @Override
    public Observable<DandelionResponse<VersionInfo>> checkVersion(CheckVersionRequest request) {
        return mRetrofitManager
                .obtainRetrofitService(LoginApi.class)
                .checkVersion(request.get_api_key(),request.getAppKey())
                .compose(RxSchedulersHelper.<DandelionResponse<VersionInfo>>io_main());
    }
}
